package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Menu;
import cn.wolfcode.mapper.MenuMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMenuService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements IMenuService {

    @Autowired
    private MenuMapper menuMapper;


    @Override
    public void save(Menu menu) {
        menuMapper.insert(menu);
    }

    @Override
    public void delete(Long id) {
        menuMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Menu menu) {
        menuMapper.updateByPrimaryKey(menu);
    }

    @Override
    public Menu get(Long id) {
        return menuMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Menu> listAll() {
        return menuMapper.selectAll();
    }

    @Override
    public PageInfo<Menu> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<Menu> menus = menuMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<Menu>(menus);
    }
}
